package engine.graphics.away3d
{
	import away3d.core.base.*;
	import away3d.core.managers.*;
	import away3d.library.assets.*;
	
	import engine.graphics.renderable.*;
	import engine.graphics.resources.*;
	import engine.graphics.shader.*;
	import engine.math.*;
	
	public class RxMaterial extends NamedAssetBase implements IAsset
	{
		private var m_texture:RxGPUTexture2D;
		private var m_shaderFamily:RxShaderFamilyBase;
		private var m_shaderFeatures:uint;
		private var m_color:RxVector4;
		private var m_emissive:RxVector4;
		private var m_scaledColor:RxVector4;
		private var m_scaledEmissive:RxVector4;
		private var m_srcBlend:uint;
		private var m_dstBlend:uint;
		private var m_alphaBlending:Boolean;
		private var m_alphaThreshold:Number;
		private var m_params:Object;
		
		public function RxMaterial(texture:RxGPUTexture2D)
		{
			this.m_texture = texture;
			if (this.m_texture != null)
			{
				this.m_texture.AddRef();
			}
			this.m_shaderFamily = null;
			this.m_shaderFeatures = 0;
			this.m_color = new RxVector4(1, 1, 1, 1);
			this.m_emissive = new RxVector4(0, 0, 0, 0);
			this.m_scaledColor = new RxVector4(1, 1, 1, 1);
			this.m_scaledEmissive = new RxVector4(0, 0, 0, 0);
			this.SetBlendMode(Stage3DProxy.BLEND_FACTOR_ONE, Stage3DProxy.BLEND_FACTOR_ZERO);
			this.m_alphaThreshold = 0;
			this.m_params = null;
		}
		
		public function GetTexture() : RxGPUTexture2D
		{
			return this.m_texture;
		}
		
		public function SetBlendMode(srcBlend:uint, dstBlend:uint) : void
		{
			this.m_srcBlend = srcBlend;
			this.m_dstBlend = dstBlend;
			this.m_alphaBlending = this.m_srcBlend != Stage3DProxy.BLEND_FACTOR_ONE || this.m_dstBlend != Stage3DProxy.BLEND_FACTOR_ZERO;
		}
		
		public function Instance() : RxMaterial
		{
			var material:* = new RxMaterial(this.m_texture);
			material.m_shaderFamily = this.m_shaderFamily;
			material.m_shaderFeatures = this.m_shaderFeatures;
			material.m_color.Copy(this.m_color);
			material.m_emissive.Copy(this.m_emissive);
			material.m_scaledColor.Copy(this.m_scaledColor);
			material.m_scaledEmissive.Copy(this.m_scaledEmissive);
			material.m_srcBlend = this.m_srcBlend;
			material.m_dstBlend = this.m_dstBlend;
			material.m_alphaBlending = this.m_alphaBlending;
			material.m_alphaThreshold = this.m_alphaThreshold;
			return material;
		}
		
		public function get assetType() : String
		{
			return AssetType.MATERIAL;
		}
	}
}